home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 2).iso / 0038 / vc.zip / VCVIEW.CPP < prev    next >
C/C++ Source or Header  |  1996-01-20  |  2KB  |  102 lines

  1. // vcview.cpp : implementation of the CVcView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "vc.h"
  6. #include <math.h>
  7.  
  8. #include "vcdoc.h"
  9. #include "vcview.h"
  10.  
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char BASED_CODE THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CVcView
  18.  
  19. IMPLEMENT_DYNCREATE(CVcView, CFormView)
  20.  
  21. BEGIN_MESSAGE_MAP(CVcView, CFormView)
  22.     //{{AFX_MSG_MAP(CVcView)
  23.     ON_WM_TIMER()
  24.     ON_WM_DESTROY()
  25.     //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CVcView construction/destruction
  30.  
  31. CVcView::CVcView()
  32.     : CFormView(CVcView::IDD)
  33. {
  34.     //{{AFX_DATA_INIT(CVcView)
  35.     m_car2 = NULL;
  36.     m_car1 = NULL;
  37.     //}}AFX_DATA_INIT
  38.     // TODO: add construction code here
  39. }
  40.  
  41. CVcView::~CVcView()
  42. {
  43. }
  44.  
  45. void CVcView::DoDataExchange(CDataExchange* pDX)
  46. {
  47.     CFormView::DoDataExchange(pDX);
  48.     //{{AFX_DATA_MAP(CVcView)
  49.     DDX_VBControl(pDX, IDC_CAR2, m_car2);
  50.     DDX_VBControl(pDX, IDC_CAR1, m_car1);
  51.     //}}AFX_DATA_MAP
  52.  
  53.     SetTimer(1,55,NULL);
  54.     srand( (unsigned)time( NULL ) );  //set randomizer seed
  55.  
  56. }
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CVcView diagnostics
  60.  
  61. #ifdef _DEBUG
  62. void CVcView::AssertValid() const
  63. {
  64.     CFormView::AssertValid();
  65. }
  66.  
  67. void CVcView::Dump(CDumpContext& dc) const
  68. {
  69.     CFormView::Dump(dc);
  70. }
  71.  
  72. CVcDoc* CVcView::GetDocument() // non-debug version is inline
  73. {
  74.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVcDoc)));
  75.     return (CVcDoc*)m_pDocument;
  76. }
  77. #endif //_DEBUG
  78.  
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CVcView message handlers
  81.  
  82. void CVcView::OnTimer(UINT nIDEvent)
  83. {
  84. float rpm,speed;
  85.  
  86.     rpm = m_car1->GetFloatProperty("Value") + (float) rand()/(float) RAND_MAX - (float) .5;
  87.     m_car1->SetFloatProperty("Value",rpm);
  88.     
  89.     speed = m_car2->GetFloatProperty("Value") + (float) 5.0 * (float) rand()/(float) RAND_MAX - (float) 2.5;
  90.     m_car2->SetFloatProperty("Value",speed);
  91.     
  92.     CFormView::OnTimer(nIDEvent);
  93. }
  94.  
  95. void CVcView::OnDestroy()
  96. {
  97.     CFormView::OnDestroy();
  98.     
  99.     KillTimer(1);
  100.     
  101. }
  102.